home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.11 Nov 88 / IAC / Editor Stuff / Edit_IAC_rtns.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-18  |  6.3 KB  |  232 lines  |  [TEXT/MPS ]

  1. # include    <types.h>
  2. # include    <memory.h>
  3. # include    <quickdraw.h>
  4. # include    <toolutils.h>
  5. # include    <windows.h>
  6. # include    <dialogs.h>
  7. # include    <menus.h>
  8. # include    <textedit.h>
  9. # include    <string.h>
  10. # include    <files.h>
  11. # include    <resources.h>
  12.  
  13. # include    <iac.h>
  14. # define PUBLIC extern
  15. # include    <Editor.h>
  16.  
  17. #define noErr          0          /* 0 for success */
  18.  
  19. /**
  20.  *    Routine: Set Current Extent
  21.  *
  22.  *        This is a local routine to set the fields in the 'current extent'
  23.  *    structure in the window data record. It is called by both hotCopy and
  24.  *    hotPaste routines, since by definitions the extents they define become
  25.  *    the 'current extent'.
  26.  */
  27.  
  28. # define __SEG__ Main
  29. void    set_curr_ext(the_data_H, which)
  30.     win_dataH    the_data_H;        /* data associated with the window */
  31.     short        which;            /* # of extent which is now current */
  32. {
  33. extentH            the_extH;            /* handle to extent block */
  34. exTable            ext_recs;
  35.  
  36.     the_extH = (**the_data_H).the_extents;
  37.     ext_recs = *the_extH;
  38.  
  39.     curr_ext.src_doc =     ext_recs[which].src_doc;
  40.     curr_ext.hat_check = ext_recs[which].hat_check;
  41.     curr_ext.ed_level =    ext_recs[which].ed_level;
  42.     curr_ext.ext_strt =    ext_recs[which].ext_strt;
  43.     curr_ext.ext_end =    ext_recs[which].ext_end;
  44. }
  45.  
  46.  
  47. /**
  48.  *    Routine: do_hotCopy
  49.  *
  50.  *        This routine is responsible for creating a new dependency source and
  51.  *    notifying the IAC driver. It is called primarily by the "source" program.
  52.  */
  53.  
  54. # define __SEG__ Main
  55. void    do_hotCopy()
  56.  
  57. {
  58. win_dataH        the_data_H;            /* data associated with a window */
  59. TEHandle        TextH;                /* The TextEdit handle */
  60. extentH            the_extH;            /* handle to extent block */
  61. exTable            ext_recs;
  62. long            the_doc;            /* local copies due to memory mashing */
  63. short            slot_ID, h_check, the_ed;
  64. short            e_cnt;
  65. short            item_hit;            /* error processing */
  66. Str255            err_str, str2;
  67.  
  68. short            iac_err = noErr;
  69. Boolean            in_extent = false;
  70.  
  71. extern    Boolean    chk_extent();        /* sets "current extent" if found */
  72. extern    void    add_display_cmd();    /* update 'Links' menu */
  73. extern    void    set_curr_ext();        /* update global structure */
  74.  
  75. extern    Boolean    ext_active;
  76.  
  77.      the_data_H = (win_dataH) GetWRefCon (myWindow);
  78.     the_extH =     (**the_data_H).the_extents;
  79.     TextH =         (**the_data_H).wind_TEH;
  80.     the_doc =     (**the_data_H).doc_ID;
  81.     slot_ID =     (**the_data_H).the_slot;
  82.     e_cnt =         (**the_data_H).ext_cnt;
  83.     h_check =     0;
  84.  
  85.     if (!chk_extent(TextH, the_extH, (**the_data_H).ext_cnt))
  86.     {
  87.         iac_err = iac_add_dependency(&the_doc, &slot_ID, &h_check, &the_ed);    
  88.         if (iac_err == noErr)
  89.         {
  90.             SetHandleSize ((Handle)the_extH, sizeof(extent) * (e_cnt+1));
  91.             ext_recs = *the_extH;
  92.             ext_recs[e_cnt].hat_check = h_check;
  93.             ext_recs[e_cnt].ed_level =  the_ed;
  94.             ext_recs[e_cnt].ext_strt =  (**TextH).selStart;
  95.             ext_recs[e_cnt].ext_end =    (**TextH).selEnd;
  96.             ext_recs[e_cnt].src_doc =   the_doc;
  97.             set_curr_ext(the_data_H,e_cnt);
  98.             
  99.             curr_ext_no = e_cnt;
  100.             e_cnt += 1;
  101.             (**the_data_H).doc_ID =      the_doc;    /* update window data */
  102.             (**the_data_H).the_slot = slot_ID;
  103.             (**the_data_H).ext_cnt =  e_cnt;
  104.             (**the_data_H).dirty =      true;        /* so we save extents */
  105.             ext_active = true;
  106.             
  107.             iac_err = ext_write(TextH,
  108.                                 (**TextH).selStart,
  109.                                 ((**TextH).selEnd - (**TextH).selStart),
  110.                                 the_doc,
  111.                                 h_check,
  112.                                 &the_ed);
  113.  
  114.             add_display_cmd(curr_ext_no, e_cnt);    /* update menu */
  115.         }
  116.         else    /* IAC alert here */
  117.         {
  118.             NumToString ((long)iac_err, &err_str);
  119.             ParamText (&err_str, "Hot Copy", nil, nil);
  120.             item_hit = StopAlert(IAC_ERR_ALRT, nil);
  121.         }
  122.     }
  123.     else    /* already-in-extent alert */
  124.     {
  125.         ParamText ("\"already-in-extent\"", "Hot Copy", nil, nil);
  126.         item_hit = StopAlert(IAC_ERR_ALRT, nil);
  127.     }
  128. }
  129.  
  130.  
  131. /**
  132.  * Routine: do_hotPaste
  133.  *
  134.  *        This routine is responsible for completing a new dependency and
  135.  *    notifying the IAC driver. It is called primarily by the "target" program.
  136.  *
  137.  *    The dependencies are stored in the array in ascending sequence to make
  138.  *    updating simpler. See the header for poll_iac() for details.
  139.  */
  140.  
  141. # define __SEG__ Main
  142. void    do_hotPaste()
  143.  
  144. {
  145. win_dataH        the_data_H;            /* data associated with a window */
  146. TEHandle        TextH;                /* The TextEdit handle */
  147. extentH            the_extH;            /* handle to extent block */
  148. exTable            ext_recs;
  149. long            the_doc;            /* local copies due to memory mashing */
  150. short            slot_ID, h_check;
  151. short            e_cnt, startt;
  152. short            the_ed;
  153. short            item_hit;            /* error processing */
  154. Str255            err_str, str2;
  155.  
  156. short            i = 0;
  157. short            iac_err = noErr;
  158. Boolean            in_extent = false;
  159.  
  160. extern    Boolean    chk_extent();        /* sets "current extent" if found */
  161. extern    void    add_display_cmd();    /* update 'Links' menu */
  162.  
  163. extern    Boolean    ext_active;
  164.  
  165.      the_data_H = (win_dataH) GetWRefCon (myWindow);
  166.     the_extH =     (**the_data_H).the_extents;
  167.     TextH =         (**the_data_H).wind_TEH;
  168.     slot_ID =     (**the_data_H).the_slot;
  169.     e_cnt =         (**the_data_H).ext_cnt;
  170.     the_doc =     0;        /* just link to "available" */
  171.     h_check =     0;
  172.     
  173.     if (!chk_extent(TextH, the_extH, e_cnt))
  174.     {
  175.         iac_err = iac_complete_dependency(&the_doc, &slot_ID, &h_check);
  176.         if (iac_err == noErr)    /* save "location" in TERec as extent */
  177.         {
  178.             (**the_data_H).the_slot = slot_ID;    /* update window data */
  179.             ext_active = true;
  180.             startt = (**TextH).selStart;
  181.             SetHandleSize ((Handle)the_extH, sizeof(extent) * (e_cnt+1));
  182.  
  183.             /* walk extent table to find entry to insert BEFORE */
  184.             ext_recs = *the_extH;
  185.             while (i<e_cnt)
  186.             {
  187.                 if ( (ext_recs[i].ext_strt==0)             /* at end of table */
  188.                   || (ext_recs[i].ext_strt>startt) )    /* table entry bigger */
  189.                 {
  190.                     /* move tail of table to make space */
  191.                     BlockMove(&ext_recs[i],
  192.                               &ext_recs[i+1],
  193.                               (e_cnt - i) * sizeof(extent));
  194.                     break;
  195.                 }
  196.                 else
  197.                 {
  198.                     i += 1;
  199.                 }
  200.             }
  201.  
  202.             ext_recs[i].hat_check = h_check;            /* fill in table entry */
  203.             ext_recs[i].ext_strt =  (**TextH).selStart;
  204.             ext_recs[i].ext_end  =  (**TextH).selEnd;
  205.             ext_recs[i].src_doc =   the_doc;
  206.             set_curr_ext(the_data_H,i);
  207.  
  208.             /* now read data from newly connected link */
  209.             the_ed = 0;
  210.             iac_err = ext_read(myWindow, &the_ed, i);
  211.             
  212.             extent_count += 1;                    /* global count */
  213.             curr_ext_no = i;
  214.             (**the_data_H).ext_cnt = e_cnt + 1;
  215.             (**the_data_H).dirty =     true;
  216.             add_display_cmd(i, extent_count);        /* update menu */
  217.  
  218.         }
  219.         else
  220.         {
  221.             NumToString ((long)iac_err, &err_str);
  222.             ParamText (&err_str, "Hot Paste", nil, nil);
  223.             item_hit = StopAlert(IAC_ERR_ALRT, nil);
  224.         }
  225.     }
  226.     else    /* already-in-extent alert */
  227.     {
  228.         ParamText ("\"already-in-extent\"", "Hot Paste", nil, nil);
  229.         item_hit = StopAlert(IAC_ERR_ALRT, nil);
  230.     }
  231. }
  232.